﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ZoneInZone.CApZZZoneInZoneApp
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ZoneInZone;

public class CApZZZoneInZoneApp
{
  private CZZZoneInZoneSpheresManager _spheresManager = new CZZZoneInZoneSpheresManager();
  private CApZZZoneInZoneCollisionsManager _collisionManager;
  private LinkedList<Location> _locations = new LinkedList<Location>();
  private List<Zone> _highlightedZones = new List<Zone>();
  private TxColor _zoneColor;
  private TxColor _selectedZoneColor;
  private ITxRoboticOrderedCompoundOperation _roboticOperation;
  private ITxOrderedCompoundOperation _operation;

  public bool IsSelectionChangedInternally { get; set; }

  public CApZZZoneInZoneApp()
  {
    this._zoneColor = new TxColor((byte) 131, (byte) 131, (byte) 181);
    this._zoneColor.Transparency = 0.5;
    this._selectedZoneColor = TxColor.FromBgrColor(TxApplication.Options.Color.SolidColor);
    this._selectedZoneColor.Transparency = 0.5;
    this._collisionManager = new CApZZZoneInZoneCollisionsManager(this._zoneColor);
  }

  private void GetRoboticOperationFromActiveSelection(
    ref ITxOrderedCompoundOperation operation,
    ref ITxRoboticOrderedCompoundOperation roboticOperation)
  {
    if (TxApplication.ActiveSelection.TotalCount <= 0)
      return;
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(new Type[2]
    {
      typeof (ITxRoboticOrderedCompoundOperation),
      typeof (TxRoboticSeamOperation)
    }));
    if (filteredItems == null || ((Collection<ITxObject>) filteredItems).Count != 1)
      return;
    if (((Collection<ITxObject>) filteredItems)[0] is ITxRoboticOrderedCompoundOperation)
    {
      operation = ((Collection<ITxObject>) filteredItems)[0] as ITxOrderedCompoundOperation;
      roboticOperation = ((Collection<ITxObject>) filteredItems)[0] as ITxRoboticOrderedCompoundOperation;
    }
    else
    {
      if (!(((Collection<ITxObject>) filteredItems)[0] is TxRoboticSeamOperation) || !(((Collection<ITxObject>) filteredItems)[0].Collection is ITxRoboticOrderedCompoundOperation))
        return;
      operation = ((Collection<ITxObject>) filteredItems)[0] as ITxOrderedCompoundOperation;
      roboticOperation = ((Collection<ITxObject>) filteredItems)[0].Collection as ITxRoboticOrderedCompoundOperation;
    }
  }

  private bool IsThereAnyOperationInActiveSelection()
  {
    bool flag = false;
    if (TxApplication.ActiveSelection.TotalCount > 0)
    {
      foreach (ITxObject allItem in (Collection<ITxObject>) TxApplication.ActiveSelection.GetAllItems())
      {
        if (allItem is ITxOperation && !(allItem is ITxLocationOperation))
        {
          flag = true;
          break;
        }
      }
    }
    return flag;
  }

  private void ListenForOperationChangeEvents()
  {
    ((ITxObjectCollection) this._operation).ItemsAdded += new TxObjectCollection_ItemsAddedEventHandler(this._operation_ItemsAdded);
    ((ITxObjectCollection) this._operation).ItemsRemoved += new TxObjectCollection_ItemsRemovedEventHandler(this._operation_ItemsRemoved);
    ((ITxObject) this._operation).Deleted += new TxObject_DeletedEventHandler(this._operation_Deleted);
    ((ITxOrderedObjectCollection) this._operation).ChildMoved += new TxOrderedObjectCollection_ChildMovedEventHandler(this._operation_ChildMoved);
    this.ListenForLocationsChangeEvents();
  }

  private void StopListeningForOperationChangeEvents()
  {
    if (this._operation == null || !((ITxObject) this._operation).IsValid())
      return;
    ((ITxObjectCollection) this._operation).ItemsAdded -= new TxObjectCollection_ItemsAddedEventHandler(this._operation_ItemsAdded);
    ((ITxObjectCollection) this._operation).ItemsRemoved -= new TxObjectCollection_ItemsRemovedEventHandler(this._operation_ItemsRemoved);
    ((ITxObject) this._operation).Deleted -= new TxObject_DeletedEventHandler(this._operation_Deleted);
    ((ITxOrderedObjectCollection) this._operation).ChildMoved -= new TxOrderedObjectCollection_ChildMovedEventHandler(this._operation_ChildMoved);
    this.StopListeningForLocationsChangeEvents();
  }

  private void ListenForRoboticOperationChangeEvents()
  {
    this._roboticOperation.RobotSet += new TxRoboticOrderedCompoundOperation_RobotSetEventHandler(this._roboticOperation_RobotSet);
    ((ITxObject) this._roboticOperation).Deleted += new TxObject_DeletedEventHandler(this._operation_Deleted);
  }

  private void StopListeningForRoboticOperationChangeEvents()
  {
    if (this._roboticOperation == null || !((ITxObject) this._roboticOperation).IsValid())
      return;
    this._roboticOperation.RobotSet -= new TxRoboticOrderedCompoundOperation_RobotSetEventHandler(this._roboticOperation_RobotSet);
    ((ITxObject) this._roboticOperation).Deleted -= new TxObject_DeletedEventHandler(this._operation_Deleted);
  }

  private void ListenForLocationsChangeEvents()
  {
    foreach (Location location in this._locations)
    {
      if (location.Loc is ITxRoboticLocationOperation)
        this.ListenForLocationParametersChangeEvents(location.Loc as ITxRoboticLocationOperation);
    }
  }

  private void StopListeningForLocationsChangeEvents()
  {
    foreach (Location location in this._locations)
    {
      if (location.Loc is ITxRoboticLocationOperation)
        this.StopListeningForLocationParametersChangeEvents(location.Loc as ITxRoboticLocationOperation);
    }
  }

  private void ListenForLocationParametersChangeEvents(ITxRoboticLocationOperation loc)
  {
    ((ITxRoboticOperation) loc).ParameterSet += new TxRoboticOperation_ParameterSetEventHandler(this.Loc_ParameterSet);
    ((ITxRoboticOperation) loc).ParameterRemoved += new TxRoboticOperation_ParameterRemovedEventHandler(this.Loc_ParameterRemoved);
  }

  private void StopListeningForLocationParametersChangeEvents(ITxRoboticLocationOperation loc)
  {
    ((ITxRoboticOperation) loc).ParameterSet -= new TxRoboticOperation_ParameterSetEventHandler(this.Loc_ParameterSet);
    ((ITxRoboticOperation) loc).ParameterRemoved -= new TxRoboticOperation_ParameterRemovedEventHandler(this.Loc_ParameterRemoved);
  }

  private void _roboticOperation_RobotSet(
    object sender,
    TxRoboticOrderedCompoundOperation_RobotSetEventArgs args)
  {
    this.ShowZonePreview();
  }

  private LinkedListNode<Location> FindLocationNode(
    ITxLocationOperation location,
    out int oldPosIndex)
  {
    oldPosIndex = -1;
    LinkedListNode<Location> locationNode = (LinkedListNode<Location>) null;
    if (location != null)
    {
      oldPosIndex = 0;
      LinkedListNode<Location> linkedListNode = this._locations.First;
      while (linkedListNode != null)
      {
        if (linkedListNode.Value.Loc == location)
        {
          locationNode = linkedListNode;
          break;
        }
        linkedListNode = linkedListNode.Next;
        ++oldPosIndex;
      }
    }
    if (locationNode == null)
      oldPosIndex = -1;
    return locationNode;
  }

  private LinkedListNode<Location> GetLocationNode(int pos)
  {
    LinkedListNode<Location> locationNode = this._locations.First;
    if (pos >= 0 && pos < this._locations.Count)
    {
      for (int index = 0; index != pos; ++index)
        locationNode = locationNode.Next;
    }
    return locationNode;
  }

  private void _operation_ItemsAdded(object sender, TxObjectCollection_ItemsAddedEventArgs args)
  {
    if (this._roboticOperation == null || this._roboticOperation.Robot == null)
      return;
    foreach (ITxObject itxObject in (Collection<ITxObject>) args.Items)
    {
      if (itxObject is ITxLocationOperation loc1)
      {
        LinkedListNode<Location> locNode = this._locations.AddLast(new Location(loc1));
        if (loc1 is ITxRoboticLocationOperation loc)
        {
          double locationZoneRadius = CApZZZoneInZoneApp.GetLocationZoneRadius(loc, this._roboticOperation);
          if (locationZoneRadius > 0.0)
            locNode.Value.Zone = this.CreateZone(loc, locationZoneRadius);
          this.ListenForLocationParametersChangeEvents(loc);
        }
        this._collisionManager.RefreshCollisionColoringArroundNode(locNode);
      }
    }
  }

  private void _operation_ChildMoved(
    object sender,
    TxOrderedObjectCollection_ChildMovedEventArgs args)
  {
    if (args.NewIndex < 0 || args.NewIndex >= this._locations.Count)
      return;
    ITxLocationOperation location = CApZZZoneInZoneRobotControllerUtilities.GetLocation((ITxOrderedObjectCollection) this._operation, args.NewIndex);
    if (location == null)
      return;
    int oldPosIndex;
    LinkedListNode<Location> locationNode = this.FindLocationNode(location, out oldPosIndex);
    if (locationNode == null || oldPosIndex == args.NewIndex)
      return;
    LinkedListNode<Location> linkedListNode = this.GetLocationNode(args.NewIndex);
    LinkedListNode<Location> locNode = locationNode.Next ?? locationNode.Previous;
    this._locations.Remove(locationNode);
    if (linkedListNode != null)
    {
      if (args.NewIndex < oldPosIndex)
      {
        this._locations.AddBefore(linkedListNode, locationNode);
        linkedListNode = linkedListNode.Previous;
      }
      else
      {
        this._locations.AddAfter(linkedListNode, locationNode);
        linkedListNode = linkedListNode.Next;
      }
    }
    else
      this._locations.AddFirst(locationNode);
    this._collisionManager.RefreshCollisionColoringArroundNode(locNode);
    this._collisionManager.RefreshCollisionColoringArroundNode(linkedListNode);
  }

  private void _operation_ItemsRemoved(object sender, TxObjectCollection_ItemsRemovedEventArgs args)
  {
    TxObjectList locations = new TxObjectList();
    if (args.Items != null && ((Collection<ITxObject>) args.Items).Count > 0)
    {
      ((TxObjectList<ITxObject>) locations).AddRange((TxObjectList<ITxObject>) args.Items);
    }
    else
    {
      for (LinkedListNode<Location> linkedListNode = this._locations.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
      {
        if (!((ITxObject) linkedListNode.Value.Loc).IsValid())
          ((Collection<ITxObject>) locations).Add((ITxObject) linkedListNode.Value.Loc);
      }
    }
    this.RemoveLocations(locations);
  }

  private void Location_AbsoluteLocationChanged(
    object sender,
    TxLocatableObject_AbsoluteLocationChangedEventArgs args)
  {
    ITxLocationOperation locationOperation = sender as ITxLocationOperation;
    LinkedListNode<Location> locNode = (LinkedListNode<Location>) null;
    for (LinkedListNode<Location> linkedListNode = this._locations.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
    {
      if (linkedListNode.Value.Loc == locationOperation)
      {
        locNode = linkedListNode;
        break;
      }
    }
    if (locNode == null || locNode.Value.Zone == null)
      return;
    locNode.Value.Zone.Sphere.AbsoluteLocation = (locationOperation as ITxLocatableObject).AbsoluteLocation;
    this._collisionManager.RefreshCollisionColoringArroundNode(locNode);
  }

  private void _operation_Deleted(object sender, TxObject_DeletedEventArgs args)
  {
    this.HideZonePreviewIfAvailable();
  }

  private bool RemoveLocation(LinkedListNode<Location> locationNode, bool updateCollisionState = true)
  {
    bool flag = false;
    if (locationNode.Value.Zone != null)
    {
      this.DeleteZone(locationNode);
      flag = true;
    }
    LinkedListNode<Location> locNode = locationNode.Next != null ? locationNode.Next : locationNode.Previous;
    this._locations.Remove(locationNode);
    if (updateCollisionState && locNode != null)
      this._collisionManager.RefreshCollisionColoringArroundNode(locNode);
    return flag;
  }

  private void DeleteZone(LinkedListNode<Location> locNode)
  {
    Zone zone = locNode.Value.Zone;
    if (zone == null)
      return;
    if (TxManipulator.op_Inequality(zone.Sphere, (ITxObject) null) && zone.Sphere.IsValid())
      zone.Sphere.Delete();
    locNode.Value.Zone = (Zone) null;
    if (!(locNode.Value.Loc is ITxLocatableObject loc))
      return;
    loc.AbsoluteLocationChanged -= new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Location_AbsoluteLocationChanged);
  }

  private static Dictionary<ITxRoboticLocationOperation, double> GetLocationsWithZones(
    List<ITxLocationOperation> locations,
    ITxRoboticOrderedCompoundOperation roboticOperation)
  {
    Dictionary<ITxRoboticLocationOperation, double> locationsWithZones = new Dictionary<ITxRoboticLocationOperation, double>();
    foreach (ITxLocationOperation location in locations)
    {
      if (location is ITxRoboticLocationOperation locationOperation && CApZZZoneInZoneRobotControllerUtilities.GetLocationZoneParameters((ITxRoboticOperation) locationOperation, roboticOperation).Count > 0)
      {
        double locationZoneRadius = CApZZZoneInZoneApp.GetLocationZoneRadius(locationOperation, roboticOperation);
        if (locationZoneRadius > 0.0)
          locationsWithZones.Add(locationOperation, locationZoneRadius);
      }
    }
    return locationsWithZones;
  }

  private static double GetLocationZoneRadius(
    ITxRoboticLocationOperation loc,
    ITxRoboticOrderedCompoundOperation operation)
  {
    double locationZoneRadius = 0.0;
    ArrayList locationZoneParameters = CApZZZoneInZoneRobotControllerUtilities.GetLocationZoneParameters((ITxRoboticOperation) loc, operation);
    if (locationZoneParameters.Count > 0)
      locationZoneRadius = (double) CApZZZoneInZoneRobotControllerUtilities.GetZoneRadius(locationZoneParameters[0] as string);
    return locationZoneRadius;
  }

  private Zone CreateZone(ITxRoboticLocationOperation loc, double radius)
  {
    Zone zone = (Zone) null;
    if (loc is ITxLocatableObject itxLocatableObject1)
    {
      TxManipulator sphere = this._spheresManager.CreateSphere(itxLocatableObject1.AbsoluteLocation, ((ITxObject) itxLocatableObject1).Name + "ZoneManipulator", this._zoneColor, radius);
      if (TxManipulator.op_Inequality(sphere, (ITxObject) null))
      {
        zone = new Zone(sphere, radius);
        if (loc is ITxLocatableObject itxLocatableObject)
          itxLocatableObject.AbsoluteLocationChanged += new TxLocatableObject_AbsoluteLocationChangedEventHandler(this.Location_AbsoluteLocationChanged);
      }
    }
    return zone;
  }

  private void Loc_ParameterSet(object sender, TxRoboticOperation_ParameterSetEventArgs args)
  {
    if (!(args.ParamName == "RRS_ZONE_NAME") || !(sender is ITxRoboticLocationOperation locationOperation))
      return;
    LinkedListNode<Location> locationNode = this.FindLocationNode((ITxLocationOperation) locationOperation, out int _);
    bool flag = false;
    if (locationNode != null)
    {
      double locationZoneRadius = CApZZZoneInZoneApp.GetLocationZoneRadius(locationOperation, this._roboticOperation);
      if (locationZoneRadius > 0.0)
      {
        if (locationNode.Value.Zone == null)
        {
          Zone zone = this.CreateZone(locationOperation, locationZoneRadius);
          if (zone != null)
          {
            locationNode.Value.Zone = zone;
            flag = true;
          }
        }
        else if (locationZoneRadius != locationNode.Value.Zone.Radius)
          flag = this.UpdateZoneRadius(locationNode, locationZoneRadius);
      }
      else if (locationNode.Value.Zone != null)
      {
        this.DeleteZone(locationNode);
        flag = true;
      }
    }
    this._collisionManager.RefreshCollisionColoringArroundNode(locationNode);
    if (!flag)
      return;
    TxApplication.RefreshDisplay();
  }

  private void Loc_ParameterRemoved(
    object sender,
    TxRoboticOperation_ParameterRemovedEventArgs args)
  {
    if (!(args.Parameter is TxRoboticStringParam parameter) || !(((TxRoboticParam) parameter).Type == "RRS_ZONE_NAME") || !(sender is ITxRoboticLocationOperation location))
      return;
    LinkedListNode<Location> locationNode = this.FindLocationNode((ITxLocationOperation) location, out int _);
    if (locationNode == null || locationNode.Value.Zone == null)
      return;
    this.DeleteZone(locationNode);
    this._collisionManager.RefreshCollisionColoringArroundNode(locationNode);
    TxApplication.RefreshDisplay();
  }

  private bool UpdateZoneRadius(LinkedListNode<Location> locNode, double radius)
  {
    bool flag = false;
    TxManipulator sphere1 = locNode.Value.Zone.Sphere;
    if (TxManipulator.op_Inequality(sphere1, (ITxObject) null) && sphere1.IsValid())
    {
      TxManipulator sphere2 = this._spheresManager.CreateSphere(sphere1.AbsoluteLocation, ((ITxObject) locNode.Value.Loc).Name + "ZoneManipulator", this._zoneColor, radius);
      if (TxManipulator.op_Inequality(sphere2, (ITxObject) null))
      {
        sphere1.Delete();
        locNode.Value.Zone.Sphere = sphere2;
        locNode.Value.Zone.Radius = radius;
        this._collisionManager.RefreshCollisionColoringArroundNode(locNode);
        flag = true;
      }
    }
    return flag;
  }

  private void ShowZonePreview()
  {
    bool flag = this.HideZonePreview();
    if (this._roboticOperation.Robot == null)
      return;
    this.CreateLocations();
    bool zones = this.CreateZones();
    if (!(flag | zones))
      return;
    TxApplication.RefreshDisplay();
  }

  private bool HideZonePreview() => this.RemoveAllLocations();

  private void CreateLocations()
  {
    foreach (ITxLocationOperation operationLocation in CApZZZoneInZoneRobotControllerUtilities.GetOperationLocations((ITxOrderedObjectCollection) this._operation))
      this._locations.AddLast(new Location(operationLocation));
  }

  private bool CreateZones()
  {
    bool zones = false;
    List<ITxLocationOperation> locations = new List<ITxLocationOperation>();
    foreach (Location location in this._locations)
      locations.Add(location.Loc);
    Dictionary<ITxRoboticLocationOperation, double> locationsWithZones = CApZZZoneInZoneApp.GetLocationsWithZones(locations, this._roboticOperation);
    if (locationsWithZones.Count > 0)
    {
      foreach (KeyValuePair<ITxRoboticLocationOperation, double> keyValuePair in locationsWithZones)
      {
        Zone zone = this.CreateZone(keyValuePair.Key, keyValuePair.Value);
        if (zone != null)
        {
          LinkedListNode<Location> locationNode = this.FindLocationNode((ITxLocationOperation) keyValuePair.Key, out int _);
          if (locationNode != null)
          {
            locationNode.Value.Zone = zone;
            zones = true;
          }
        }
      }
      this._collisionManager.ColorCollidingNeighborZones(this._locations);
    }
    return zones;
  }

  private bool StopHighlightZones()
  {
    bool flag = false;
    if (this._highlightedZones.Count > 0)
    {
      flag = true;
      foreach (Zone highlightedZone in this._highlightedZones)
        TxDisplayableObjectEx.StopEmphasizeObject((ITxDisplayableObject) highlightedZone.Sphere, this._selectedZoneColor, (TxColorEmphasizePriority) 2);
      this._highlightedZones.Clear();
    }
    return flag;
  }

  private bool HighlightZonesFromTheirLocations(TxObjectList locations)
  {
    bool flag = false;
    if (this._operation != null && this._locations.Count > 0)
    {
      foreach (ITxLocationOperation location in (Collection<ITxObject>) locations)
      {
        for (LinkedListNode<Location> linkedListNode = this._locations.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
        {
          if (linkedListNode.Value.Loc == location && linkedListNode.Value.Zone != null)
          {
            TxDisplayableObjectEx.EmphasizeObject((ITxDisplayableObject) linkedListNode.Value.Zone.Sphere, this._selectedZoneColor, (TxColorEmphasizePriority) 2);
            this._highlightedZones.Add(linkedListNode.Value.Zone);
            flag = true;
            break;
          }
        }
      }
    }
    return flag;
  }

  private void SelectLocationsFromTheirZones(TxObjectList zoneManipulators)
  {
    TxObjectList txObjectList = new TxObjectList();
    if (this._operation == null || this._locations.Count <= 0)
      return;
    foreach (TxManipulator zoneManipulator in (Collection<ITxObject>) zoneManipulators)
    {
      foreach (Location location in this._locations)
      {
        if (location.Zone != null && TxManipulator.op_Equality(location.Zone.Sphere, (ITxObject) zoneManipulator))
          ((Collection<ITxObject>) txObjectList).Add((ITxObject) location.Loc);
      }
    }
    if (((Collection<ITxObject>) txObjectList).Count <= 0)
      return;
    TxApplication.ActiveSelection.AddItems(txObjectList);
  }

  private void RemoveLocations(TxObjectList locations)
  {
    foreach (ITxObject location in (Collection<ITxObject>) locations)
    {
      if (location is ITxLocationOperation)
      {
        LinkedListNode<Location> locationNode = this.FindLocationNode(location as ITxLocationOperation, out int _);
        if (locationNode != null)
        {
          this.RemoveLocation(locationNode);
          if (location is ITxRoboticLocationOperation)
            this.StopListeningForLocationParametersChangeEvents(location as ITxRoboticLocationOperation);
        }
      }
    }
  }

  private bool RemoveAllLocations()
  {
    bool flag = false;
    LinkedListNode<Location> next;
    for (LinkedListNode<Location> locationNode = this._locations.First; locationNode != null; locationNode = next)
    {
      next = locationNode.Next;
      flag |= this.RemoveLocation(locationNode, false);
    }
    return flag;
  }

  public void ShowZonePreviewIfAvailable()
  {
    ITxOrderedCompoundOperation operation = (ITxOrderedCompoundOperation) null;
    ITxRoboticOrderedCompoundOperation roboticOperation = (ITxRoboticOrderedCompoundOperation) null;
    this.GetRoboticOperationFromActiveSelection(ref operation, ref roboticOperation);
    if (operation != null && roboticOperation != null)
    {
      if (operation == this._operation || !((ITxObject) operation).IsValid() || !((ITxObject) roboticOperation).IsValid())
        return;
      this.StopListeningForOperationChangeEvents();
      this.StopListeningForRoboticOperationChangeEvents();
      this._operation = operation;
      this._roboticOperation = roboticOperation;
      this.ShowZonePreview();
      this.ListenForOperationChangeEvents();
      this.ListenForRoboticOperationChangeEvents();
    }
    else
    {
      if (!this.IsThereAnyOperationInActiveSelection())
        return;
      this.HideZonePreviewIfAvailable();
    }
  }

  public void HideZonePreviewIfAvailable()
  {
    this.StopListeningForOperationChangeEvents();
    this.StopListeningForRoboticOperationChangeEvents();
    if (this.HideZonePreview())
      TxApplication.RefreshDisplay();
    this._operation = (ITxOrderedCompoundOperation) null;
    this._roboticOperation = (ITxRoboticOrderedCompoundOperation) null;
  }

  public void SynchronizeSelectionBetweenLocationsAndZones()
  {
    bool flag = this.StopHighlightZones();
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(new Type[2]
    {
      typeof (ITxLocationOperation),
      typeof (TxManipulator)
    }));
    if (((Collection<ITxObject>) filteredItems).Count > 0)
    {
      TxObjectList locations = (TxObjectList) null;
      TxObjectList zoneManipulators = (TxObjectList) null;
      foreach (ITxObject itxObject in (Collection<ITxObject>) filteredItems)
      {
        if (itxObject is ITxLocationOperation)
        {
          if (locations == null)
            locations = new TxObjectList();
          ((Collection<ITxObject>) locations).Add(itxObject);
        }
        else
        {
          if (zoneManipulators == null)
            zoneManipulators = new TxObjectList();
          ((Collection<ITxObject>) zoneManipulators).Add(itxObject);
        }
      }
      if (zoneManipulators != null && ((Collection<ITxObject>) zoneManipulators).Count > 0)
        TxApplication.ActiveSelection.RemoveItems(zoneManipulators);
      if (locations != null)
        flag |= this.HighlightZonesFromTheirLocations(locations);
      if (zoneManipulators != null)
        this.SelectLocationsFromTheirZones(zoneManipulators);
    }
    if (!flag)
      return;
    TxApplication.RefreshDisplay();
  }
}
